package com.woniuxy.woniuticket.movieinfomodule.controller;

import com.woniuxy.woniuticket.movieinfomodule.dto.UserandVip;
import com.woniuxy.woniuticket.movieinfomodule.service.impl.ProblemOfFeedbackServiceImp;
import com.woniuxy.woniuticket.pojo.ProblemOfFeedback;
import com.woniuxy.woniuticket.pojo.UsersInfo;
import com.woniuxy.woniuticket.utils.PageUtil;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @author zyf
 * @Description:TODO
 * @date 2019/6/13
 * @Version 1.0
 */
@Controller
public class ProblemOfFeedbackController {
    @Resource
    private ProblemOfFeedbackServiceImp problemOfFeedbackServiceImp;
    //展示所有反馈信息
    @RequestMapping("/problem/showProblem")
    @ResponseBody
    public Map showProblem(@RequestParam("page") int  page, @RequestParam("limit") int limit){
        //System.out.println(userandVip);

        List<ProblemOfFeedback> list = problemOfFeedbackServiceImp.showAllProblemOfFeedback();
        Map map = PageUtil.page(list,limit,page);
        return map;
    }
    //删除反馈信息
    @RequestMapping("/problem/deleProblem")
    @ResponseBody
    public String deleProblem(Integer problemId){
        String message = problemOfFeedbackServiceImp.deleProblem(problemId);
        return message;
    }

    //修改反馈信息，进度更改为已处理
    @RequestMapping("/problem/solveProblem")
    @ResponseBody
    public String solveProblem(Integer problemId){
        String message = problemOfFeedbackServiceImp.updateProblem(problemId);
        return message;
    }

    //添加反馈信息
    @RequestMapping("/problem/addProblem")
    @ResponseBody
    public String addProblem(ProblemOfFeedback problemOfFeedback, HttpSession session){
        UsersInfo user  = (UsersInfo) session.getAttribute("user");
        String message = null;
        if(user != null){//判断是否登录
            problemOfFeedbackServiceImp.addProblem(problemOfFeedback);
            message = "感谢您的支持";
        }else {
            message = "未登录";
        }
        System.out.println(message);
        return message;
    }

}
